<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        input{
            width: 300px;
            height: 30px;
        }
        button{
            width: 50px;
            height: 30px;
        }
        #p1{
            width: 400px;
            height: 400px;
            background-color:lightblue;
        }
        #p2{
            width: 400px;
            height: 400px;
            background-color:pink;
        }
    </style>
</head>
<body>
请输入数字：<input type="text">
<button>加密</button>
<p id="p1"></p>
<button>解密</button>
<p id="p2"></p>
<script>
    var inp=document.getElementsByTagName("input")[0];
    var btn=document.getElementsByTagName("button");
    var P=document.getElementsByTagName("p");
    btn[0].onclick=function(){
        var stn="";
        var str=inp.value;
        for(var i=0;i<str.length;i++){
            stn+=String.fromCharCode(str.charCodeAt(i)+400);
        }
        P[0].innerHTML=stn;
    }
    btn[1].onclick=function(){
        var stn="";
        var str=P[0].innerHTML;
        for(var i=0;i<str.length;i++){
            stn+=String.fromCharCode( str.charCodeAt(i)-400);
        }
        P[1].innerHTML=stn;
    }
</script>
</body>
</html>